const axios = require('axios');
const Q = require('q');
const qs = require('querystring');
const menudata = require( 'api/menus');       //  接口js引用
const md5 = require('js-md5');                    //   md5加密
const b64 = require('js-base64');                //   664加密
// axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8';
// axios.defaults.withCredentials = true;
// console.log( axios.defaults.xhrFields)
// * Mocking client-server processing
module.exports = {
    username:'', //  用户名称
    usertime:'',//   用户登录时间
    authorization:'',   // headr 公共的 接口请求需要  md5(  b64（data.sign + (data.userId + data.level) + data.time));


    u :'http://121.40.238.221:8011/',  //  前部分接口
    hu :'http://10.0.0.2:7788/',  //  前部分接口
    ur :'http://192.168.0.114:8000/api/SysInfo/', //
    posturl:'http://47.98.31.90:88/api/',
    posturl2:'http://192.168.0.114:9988/api/',


    // 登录
    insuranceLogin:function(data){
        var deferred = Q.defer();
        axios({
            method:'POST',
            url: 'http://192.168.0.114:9988/api/SysInfo/UserLogin?UserName='+data.loginAccount+'&UserPass='+data.loginPassword,
         //   headers:{'Authorization':'','Content-Type':'application/json;charset=utf-8'},
         //   params:{ "UserName":data.loginAccount,'UserPass':data.loginPassword},
    }).then(function (response) {
            deferred.resolve(response.data);
        }).catch(function (error) {
            console.log(error)
        });
        return deferred.promise;
    },
    // 城市列表
    insuranceCityList:function(data){
        // var deferred = Q.defer();
        // axios({
        //     method:'POST',
        //     url: 'http://192.168.0.114:9894/api/SysInfo/GetCityModel',
        //     headers:{'Authorization':'','Content-Type':'application/json;charset=utf-8'},
        //    data:{ "FLD_AREACODE":'330100'},
        // }).then(function (response) {
        //     deferred.resolve(response.data);
        // }).catch(function (error) {
        //     console.log(error)
        // });
        // return deferred.promise;
    },

    // 退出
    insurancetuichu:function(){
        var deferred = Q.defer();
        axios({
            method:'POST',
            url: this.u + 'open/logoutValidate',
            responseType: 'json',
        }).then(function (response) {
            deferred.resolve(response.data);
        }).catch(function (error) {
            console.log(error)
        });
        return deferred.promise;
    },
    // 修改密码
    changePwd:function(data){
        var deferred = Q.defer();
        axios({
            method:'POST',
            url: this.u + 'api/modifyPassword',
            data:{newPassword:md5(data.newPassword),oldPassword:md5(data.oldPassword)}
        }).then(function (response) {
            deferred.resolve(response.data);
        }).catch(function (error) {
            console.log(error)
        });
        return deferred.promise;
    },

    userData:function(data){
        var deferred = Q.defer();
        axios({
            method:'POST',
            headers:{'Authorization':this.authorization,'Content-Type':'application/json;charset=utf-8'},
            url: this.u + 'api/obtainUser',
        }).then(function (response) {
            deferred.resolve(response.data);
        }).catch(function (error) {
            console.log(error)
        });
        return deferred.promise;
    },

    //  订单统计
    orderCountList:function(data){
        var deferred = Q.defer();
        axios({
            method:'POST',
            url: this.u+ 'api/agent/statistics',
            params :data
        }).then(function (response) {
            deferred.resolve(response.data);
        }).catch(function (error) {
            console.log(error)
        });
        return deferred.promise;
    },
};

